<?php

/**
 * POSCMS框架文件
 * 二次开发时请勿修改本文件
 * 四川迅睿云软件开发有限公司 www.xunruicms.com
 */

class M_Controller extends \Poscms\Common {


    // 更新栏目数据
    protected function _update_category_total() {
        $mod = array(
            'share',
        );
        $module = $this->db->where('disabled', 0)->order_by('displayorder ASC')->get('module')->result_array();
        if ($module) {
            foreach ($module as $t) {
                $mod[] = $t['dirname'];
            }
        }
        foreach ($this->site_info as $siteid => $t) {
            foreach ($mod as $dirname) {
                $cache = $this->dcache->get('module-'.$siteid.'-'.$dirname);
                if (!$cache['category']) {
                    continue;
                }
                $table = $this->db->dbprefix($siteid . '_' . $dirname . '_category');
                if (!$this->db->query("SHOW TABLES LIKE '".$table."'")->row_array()) {
                    continue;
                }
                //
                foreach ($cache['category'] as $i => $c) {
                    if ($c['mid']) {
                        $cache['category'][$i]['total'] = $this->db->where('status', 9)->where('catid', $c['id'])->count_all_results($siteid.'_'.$c['mid'].'_index');
                    } else {
                        $cache['category'][$i]['total'] = 0;
                    }
                }
                foreach ($cache['category'] as $i => $c) {
                    if ($c['child']) {
                        $arr = explode(',', $c['childids']);
                        $cache['category'][$c['id']]['total'] = intval($cache['category'][$c['id']]['total']);
                        foreach ($arr as $i) {
                            $cache['category'][$c['id']]['total']+= $cache['category'][$i]['total'];
                        }
                    }
                }
                $this->dcache->set('module-'.$siteid.'-'.$dirname, $cache);
            }
        }
    }

    public function aaa() {
        echo 'This is POSCMS v'.DR_VERSION;
    }

    public function abc() {
        echo DR_LICENSE_ID;exit;
    }
}